package com.charges.controller;

import com.charges.vo.RestResult;
import com.charges.query.RedemptionCodeQuery;
import com.charges.service.RedemptionCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * 核销码控制器
 * @author admin
 */
@RestController
@RequestMapping("/api/redemption-code")
@Tag(name = "核销码管理", description = "核销码相关的操作")
@Validated
public class RedemptionCodeController {

    @Autowired
    private RedemptionCodeService redemptionCodeService;

    /**
     * 验证核销码有效性
     * @param redemptionCodeQuery 核销码查询条件
     * @return 核销码验证结果
     */
    @Operation(summary = "验证核销码有效性")
    @PostMapping("/validate")
    public RestResult validateRedemptionCode(@Valid @RequestBody RedemptionCodeQuery redemptionCodeQuery) {
        return redemptionCodeService.validateRedemptionCode(redemptionCodeQuery.getRedemptionCode());
    }

    /**
     * 进行权益充值
     * @param redemptionCodeQuery 核销码查询条件
     * @return 充值结果
     */
    @Operation(summary = "进行权益充值")
    @PostMapping("/recharge")
    public RestResult rechargeWithRedemptionCode(@Valid @RequestBody RedemptionCodeQuery redemptionCodeQuery) {
        return redemptionCodeService.rechargeWithRedemptionCode(redemptionCodeQuery.getRedemptionCode());
    }

    /**
     * 根据核销码查询充值金额
     * @param query 查询条件
     * @return 查询结果
     */
    @Operation(summary = "根据核销码查询充值金额")
    @PostMapping("/query-recharge-amount")
    public RestResult<Double> queryRechargeAmount(@Valid @RequestBody RedemptionCodeQuery query) {
        return redemptionCodeService.getRechargeAmountByRedemptionCode(query);
    }
}